<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    class priorityQueue {
      constructor () {
        this.items = []
        // class QueueElement {
        //   constructor (element, priority) {
        //     this.element = element
        //     this.priority = priority
        //   }
        // }
        // function QueueElement(element, priority) {
        //     this.element = element
        //     this.priority = priority
        // }
      }
      push (element, priority) {
        const ele = {}
        let index = 0
        ele.element = element
        ele.priority =priority
        while (index < this.size()) {
          if (ele.priority > this.items[index].priority) {
            return this.items.splice(index, 0, ele)
          }
          index++
        }
        this.items.push(ele)
      }
      shift () {
        return this.items.shift()
      }
      isEmpty () {
        return this.items.length === 0
      }
      size () {
        return this.items.length
      }
      front () {
        return this.items[0]
      }
      toString () {
        const result = []
        Object.keys(this.items).forEach(index => {
          result.push(this.items[index].element + this.items[index].priority, '<-')
        })
        result.pop()
        return result.join(' ')
      }
    }
    const foo = new priorityQueue()
    foo.push('bbb', 222)
    foo.push('aaa', 111)
    foo.push('ccc', 333)
    console.log(foo)
  </script>
</body>
</html>